package com.github.binarylei.hello_world.topology;

import com.github.binarylei.hello_world.bolt.PrintBolt;
import com.github.binarylei.hello_world.bolt.WriteBolt;
import com.github.binarylei.hello_world.spout.PWSpout;
import org.apache.storm.Config;
import org.apache.storm.LocalCluster;
import org.apache.storm.topology.TopologyBuilder;

/**
 * @author: leigang
 * @version: 2018-04-07
 */
public class PWTopology1 {

    public static void main(String[] args) throws InterruptedException {
        Config cfg = new Config();
        //cfg.setNumWorkers(1);
        cfg.setDebug(true);
        TopologyBuilder builder = new TopologyBuilder();
        builder.setSpout("spout", new PWSpout());
        builder.setBolt("print-bolt", new PrintBolt()).shuffleGrouping("spout");
        builder.setBolt("write-bolt", new WriteBolt()).shuffleGrouping("print-bolt");

        //1. 本地模式
        LocalCluster cluster = new LocalCluster();
        cluster.submitTopology("top1", cfg, builder.createTopology());
        Thread.sleep(20 * 1000);
        cluster.killTopology("top1");
        cluster.shutdown();

        //2. 集群模式
        //cfg.setNumWorkers(1);
        //cfg.setDebug(true);
        //StormSubmitter.submitTopology("top1", cfg, builder.createTopology());

    }
}
